/**
 * 
 */
package co.fitstart.entity.course;

import java.beans.Transient;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;

import com.demo2do.core.format.PersistentFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * @author downpour
 *
 */
@Entity
@Table(name = "course")
@DynamicUpdate
@PersistentFormat
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class Course {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /**
     * 1 experience
     * 2 given
     * 3 individual
     * 4 special
     * 5 year
     * 6 posture
     * 7 group
     * 8 online
     */
    private Long typeId;
    
    /** 课程封面 */
    private String cover;
    
    private String name;
    
    /** 课程预约开始时间 */
    private String appointStartTime;
    
    /** 课程预约结束时间 */
    private String appointEndTime;
    
    /** 是否为线上课程   */
    @Column(name = "is_online")
    private boolean online;
    
    @Enumerated(EnumType.STRING)
    private CourseType courseType;
    
    @Enumerated(EnumType.STRING)
    private CourseUnit courseUnit;
    
    /** 是否为体验课  */
    @Column(name = "is_experience")
    private boolean experience;
    
    /** 是否为团课  */
    @Column(name = "is_group")
    private boolean group;
    
    /** 是否为年卡  */
    @Column(name = "is_year")
    private boolean year;
    
    /** 是否为赠课  */
    @Column(name = "is_give")
    private boolean give;
    
    /** 总周数 */
    private int weeks;
    
    /** 总课时 */
    private int hours;
    
    /** 课程成员数 */
    private int numbers;
    
    /** 课程有效期 (周) */
    private int expires;
    
    /** 可冻结次数 */
    private int freezingNumber;
    
    /**
     * The default constructor
     */
    public Course() {
        
    }
    
    /**
     * 1 experience
     * 2 given
     * 3 individual
     * 4 special
     * 5 year
     * 6 posture
     * 7 group
     * 8 online
     */
    public String getCategoryName() {
    	if(this.typeId == 0) {
    		return "体验课-不计";
    	} else if(this.typeId == 1) {
    		return "体验课-计";
    	} else if(this.typeId == 2) {
    		return "赠课";
    	} else if(this.typeId == 3) {
    		return "常规课";
    	} else if(this.typeId == 4) {
    		return "特色课";
    	} else if(this.typeId == 9) {
    		return "特色75min";
    	} else if(this.typeId == 5) {
    		return "周期课";
    	} else if(this.typeId == 6) {
    		return "体态调整课";
    	} else if(this.typeId == 7) {
    		return "线下团课";
    	} else if(this.typeId == 8) {
    		return "线上课";
    	} else {
    		return null;
    	}
    }
    
    /**
     * 
     * @return
     */
    public CourseType decide() {
        return this.isOnline() ? CourseType.ONLINE : this.isGroup() ? CourseType.GROUP : this.isYear() ? CourseType.YEAR : CourseType.INDIVIDUAL;
    }
    
    public boolean isLongColpan() {
    	if(this.experience == true && this.courseUnit.equals(CourseUnit.NORMAL_EXPERIENCE)) {
    		return true;
    	} else if (this.courseUnit.equals(CourseUnit.SPECIAL_UNION)) {
    		return true;
    	} else {
    		return false;
    	}
    }
    /**
     * @param cover
     * @return
     */
    public Course editCover(String cover) {
        this.cover = cover;
        return this;
    }
    
    /**
     * 
     * @return
     */
    @Transient
    public String getTransferId() {
        return Long.toString(this.id);
    }
    
    /**
     * 
     * @return
     */
    @Transient
    public boolean isOffline() {
        return !this.online;
    }
    
    public boolean couldSelectCode() {
        return isOffline() && !this.group && !this.experience;
    }

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @return the typeId
	 */
	public Long getTypeId() {
		return typeId;
	}

	/**
	 * @return the cover
	 */
	public String getCover() {
		return cover;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @return the appointStartTime
	 */
	public String getAppointStartTime() {
		return appointStartTime;
	}

	/**
	 * @return the appointEndTime
	 */
	public String getAppointEndTime() {
		return appointEndTime;
	}

	/**
	 * @return the online
	 */
	public boolean isOnline() {
		return online;
	}

	/**
	 * @return the courseType
	 */
	public CourseType getCourseType() {
		return courseType;
	}

	/**
	 * @return the courseUnit
	 */
	public CourseUnit getCourseUnit() {
		return courseUnit;
	}

	/**
	 * @return the experience
	 */
	public boolean isExperience() {
		return experience;
	}

	/**
	 * @return the group
	 */
	public boolean isGroup() {
		return group;
	}

	/**
	 * @return the year
	 */
	public boolean isYear() {
		return year;
	}

	/**
	 * @return the give
	 */
	public boolean isGive() {
		return give;
	}

	/**
	 * @return the weeks
	 */
	public int getWeeks() {
		return weeks;
	}

	/**
	 * @return the hours
	 */
	public int getHours() {
		return hours;
	}

	/**
	 * @return the numbers
	 */
	public int getNumbers() {
		return numbers;
	}

	/**
	 * @return the expires
	 */
	public int getExpires() {
		return expires;
	}

	/**
	 * @return the freezingNumber
	 */
	public int getFreezingNumber() {
		return freezingNumber;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @param typeId the typeId to set
	 */
	public void setTypeId(Long typeId) {
		this.typeId = typeId;
	}

	/**
	 * @param cover the cover to set
	 */
	public void setCover(String cover) {
		this.cover = cover;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @param appointStartTime the appointStartTime to set
	 */
	public void setAppointStartTime(String appointStartTime) {
		this.appointStartTime = appointStartTime;
	}

	/**
	 * @param appointEndTime the appointEndTime to set
	 */
	public void setAppointEndTime(String appointEndTime) {
		this.appointEndTime = appointEndTime;
	}

	/**
	 * @param online the online to set
	 */
	public void setOnline(boolean online) {
		this.online = online;
	}

	/**
	 * @param courseType the courseType to set
	 */
	public void setCourseType(CourseType courseType) {
		this.courseType = courseType;
	}

	/**
	 * @param courseUnit the courseUnit to set
	 */
	public void setCourseUnit(CourseUnit courseUnit) {
		this.courseUnit = courseUnit;
	}

	/**
	 * @param experience the experience to set
	 */
	public void setExperience(boolean experience) {
		this.experience = experience;
	}

	/**
	 * @param group the group to set
	 */
	public void setGroup(boolean group) {
		this.group = group;
	}

	/**
	 * @param year the year to set
	 */
	public void setYear(boolean year) {
		this.year = year;
	}

	/**
	 * @param give the give to set
	 */
	public void setGive(boolean give) {
		this.give = give;
	}

	/**
	 * @param weeks the weeks to set
	 */
	public void setWeeks(int weeks) {
		this.weeks = weeks;
	}

	/**
	 * @param hours the hours to set
	 */
	public void setHours(int hours) {
		this.hours = hours;
	}

	/**
	 * @param numbers the numbers to set
	 */
	public void setNumbers(int numbers) {
		this.numbers = numbers;
	}

	/**
	 * @param expires the expires to set
	 */
	public void setExpires(int expires) {
		this.expires = expires;
	}

	/**
	 * @param freezingNumber the freezingNumber to set
	 */
	public void setFreezingNumber(int freezingNumber) {
		this.freezingNumber = freezingNumber;
	}
}
